How to Add A Settings Sheet
Friday, February 10, 2023
5:07 PM
- In Visual Studio Solution Explorer, right-click and Copy the Commands\Settings\GeneralSheet.cs main file
- Right click the Commands\Settings folder and choose Paste
- Right-click the new file, and Rename, replacing "GeneralSheet - Copy" with the new name, e.g., "FooSheet"
- Right-click the file and choose View Code
- Rename the GeneralSheet class and constructor to FooSheet
- Rename the nameof() line to FooSheet
- Open the FooSheet.Designer.cs and rename the partial class to FooSheet
- Double-click FooSheet.cs to open the visual designer
- Modify the UI with controls you need to implement Foo settings
- Add a new resource for the sheet title named Resx.FooSheet_Title
- In the constructor, set the Title property to Resx.FooSheet_Title
- Double-click SettingsDialog.cs to open the visual designer
- Select the tree view and edit its Nodes property
- Create a new root node
- Set the name property to fooNode
- Set the text property to Foo
- Change the order of the nodes to they are sorted alphabetically
- View code for SettingsDialog.cs
- Add Foo to the Sheets enum
- Create a new Resource called SettingsDialog_fooNode.Text with the value Foo
- In the constructor, set the tree node text to Resx.SettingsDialog_fooNode_Text
- In the Navigate method, add an item to the switch statement for FooSheet; this should match the sequence number set in the tree view for the node
- Override the CollectSettings method
- Get the appropriate SettingsCollection, preferrably using the Name property
- Set all settings for this sheet
- Return true if any of the properties have changed or were added and will require OneNote to restart in order to be recognized; return false otherwise
Come up with a name for the functional domain to control with your new settings. Existing domains include General, Images, Keyboard, etc. For the examples below, we'll use the ubiquitous "Foo" category.
Create A New FooSheet
Add FooSheet to The SettingsDialog
Collect Settings
#omwiki #omdeveloper
© 2020 Steven M Cohn. All rights reserved.
Please consider a sponsorship or one-time donation to support ongoing development
Created with OneNote.